<template>
    <div>
      <!-- 搜索结果页-头部导航 -->
      <div class="search-result-container">
        <!-- 点击实现后退效果 -->
        <van-nav-bar
          title="搜索结果"
          left-arrow
          @click-left="$router.go(-1)"
          fixed
        />
        <!-- 返回的文章列表 -->
        <div>
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh">

            <ArticleItem
            v-for="item in atticLelistArr"
            :key="item.art_id"
            :obj="item"
            :isShow='false'
            ></ArticleItem>
             <van-list
          v-model="loading"
          finished-text="没有更多了"
          loading-text="获取更多中..."
          @load="onLoad"
          offset="50"
          :immediate-check="false"
        >
          <!-- 文章列表 -->
          <ArticleItem
            v-for="item in atticLelistArr"
            :key="item.art_id"
            :obj="item"
          >
          </ArticleItem>
        </van-list>
      </van-pull-refresh>
        </div>
      </div>

    </div>
</template>

<script>
import { getSearchAPI } from '@/api'
import ArticleItem from '@/views/Home/ArticleItem'
export default {
  components: {
    ArticleItem
  },
  name: 'SearchResult',
  data () {
    return {
      atticLelistArr: [],
      page: 1,
      loading: false,
      isLoading: false
    }
  },
  created () {
    this.getList()
  },
  methods: {
    async getList () {
      const params = {
        page: this.page,
        per_page: 10,
        q: this.$route.query.kw
      }
      const res = await getSearchAPI(params)
      res.data.data.results.forEach(item => {
        this.atticLelistArr.push(item)
      })
      this.loading = false
    },
    onLoad () {
      this.page++
      this.getList()
    },
    // 下拉刷新事件
    onRefresh () {
      this.getList()
      this.$toast('刷新成功')
    }
  }
}
</script>

<style lang="less" scoped>
.search-result-container {
  padding-top: 46px;
}
</style>
